<template>
  <el-dialog :title="title" :append-to-body="checkObj.isChildren" :visible.sync="dialogFormVisible" @close="cancelDialog">
    <el-form>
        <el-form-item label="结论">
            <el-radio-group v-model="statusValue">
                <el-radio :label="1" border>通过</el-radio>
                <el-radio :label="0" border>驳回</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="意见">
            <el-input type="textarea" :rows="2" placeholder="请输入意见"  v-model="option"/>
        </el-form-item>
        <el-form-item label="附件">
            <input type="file" @change="fileChange"/>
        </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancelDialog">取消</el-button>
      <el-button type="primary" @click.stop="submitForm()">提交</el-button>
    </div>
  </el-dialog>
</template>
<script>
  export default {
    data(){
      return {
        dialogFormVisible: false,
        statusValue:1,
        option: '',
        file:''

      };
    },
    props: {
      title: {
        type: String
      },
      value: {
        type: Boolean
      },
      checkObj: {
        type: Object,
        default: {
          id: '',
          url: '',
          statusCode: '',
          opinionCode: '',
          fileCode:'',
          isChildren:false
        }
      }
    },
    methods:{
      fileChange(event){
        this.file = event.target.files[0];
      },
      cancelDialog(){
        this.dialogFormVisible = false;
        this.$emit('input', false);
        this.$emit('checkSuc');
      },
      submitForm(){
        let _this = this;
        let formData = new FormData();
        console.debug("id："+this.checkObj.id);
        formData.append('id',this.checkObj.id);
        formData.append(this.checkObj.statusCode,this.statusValue);
        formData.append(this.checkObj.opinionCode,this.option);
        formData.append(this.checkObj.fileCode,this.file);
        let config = {
            headers: {  
              'Content-Type': 'multipart/form-data'  
            }  
          };
        this.axios.post(this.checkObj.url,formData,config).
        then(res=>{
          let result = res.data;
          if(result.success){
           this.showMsg('success','操作成功');
           this.cancelDialog();
          }else{
            this.showMsg('error',result.message);
          }
        }).catch(e=>{
          this.showMsg('error',e);
        });
        
      }
    },
    watch:{
      value(val){
        debugger;
        this.dialogFormVisible = val;
      }
    }
  }
</script>
<style>
  .el-checkbox__input.is-checked+.el-checkbox__label{
    color: #606266;
  }
</style>
